package com.orhon.smartcampus.modules.baseinfo.fetcher;

import com.orhon.smartcampus.modules.baseinfo.dao.MessageCategoryDao;
import com.orhon.smartcampus.modules.baseinfo.entity.MessageCategory;
import com.orhon.smartcampus.modules.baseinfo.gqlModel.GQLMessageCategory;
import com.orhon.smartcampus.modules.baseinfo.mm.MessageCategoryMapper;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息分类管理列表
 */
@Component
public class MessageCategoryFetcher implements DataFetcher {

    @Autowired
    MessageCategoryDao messageCategoryDao;

    @Override
    public Object get(DataFetchingEnvironment env) throws Exception {

        int id = Integer.parseInt(env.getArgument("id").toString());
        String hql = "from MessageCategory as category where category.deletedAt = null and category.id = "+id;

        MessageCategory messageCategory = messageCategoryDao.findId(hql , null );
        if(messageCategory!=null) {
            GQLMessageCategory gqlMessageCategory = MessageCategoryMapper.MAPPER.toMessageCategory(messageCategory);
            return gqlMessageCategory;
        }

        return null;
    }

}
